<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Crew;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Http\Controllers\AdminController;

class CrewController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Crew(), function (Grid $grid) {
            // $grid->column('teacher_bn');
            $grid->column('mobile')->editable();
            // $grid->column('avatar');
            $grid->column('crew_id', '船员ID');
            $grid->column('crew_name', '船员姓名');
            $grid->column('mobile', '手机号')->editable();
            $grid->column('created_at', '注册时间')->display(function($time) {
                return $time->format('Y-m-d H:i:s');
            })->sortable();
            $grid->column('updated_at')->display(function($time) {
                return $time->format('Y-m-d H:i:s');
            })->sortable();

            // 设置默认排序
            $grid->model()->orderBy('created_at', 'desc');

            // 禁用创建
            $grid->disableCreateButton();
            // 禁用行选择器
            $grid->disableRowSelector();
            // 禁用操作
            $grid->disableActions();
            /*
            // 禁用详情按钮
            $grid->disableViewButton();
            // 禁用编辑按钮
            $grid->disableEditButton();
            // 禁用删除按钮
            $grid->disableDeleteButton();
            // 显示快捷编辑按钮
            $grid->showQuickEditButton();
            */
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('crew_id', '船员ID');
                $filter->like('crew_name', '船员姓名');
                $filter->like('mobile', '手机号');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Teacher(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('teacher_name');
            $show->field('teacher_bn');
            $show->field('mobile');
            $show->field('avatar');
            $show->field('course_id');
            $show->field('start_time');
            $show->field('work_year');
            $show->field('desc');
            $show->field('twocode');
            $show->field('course_fee');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Teacher(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('teacher_name');
            $form->text('teacher_bn');
            $form->text('mobile');
            $form->text('avatar');
            $form->text('course_id');
            $form->text('start_time');
            $form->text('work_year');
            $form->text('desc');
            $form->text('twocode');
            $form->text('course_fee');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
